<template>
  <div class="amazon-list-wrap table-gl-w">
    <div class="search-w table-filter-form">
      <FilterTable :filterItem="filterItem" :maxNum="8" :isReset="true" @search="searchByVal">
        <template #filterItemLeft>
          <div class="filter-item" style="margin-right: 8px; margin-bottom: 5px">
            <a-radio-group type="button" v-model="searchVal.modelType" @change="searchByVal">
              <a-radio :value="1">子ASIN</a-radio>
              <a-radio :value="2">父ASIN</a-radio>
            </a-radio-group>
          </div>
        </template>
      </FilterTable>
    </div>
    <div class="table-gl-con">
      <TableWrap style="flex: 1" @refresh="getGoodsList">
        <template #headerLeft>
          <a-space>
            <a-button type="primary" size="medium" v-if="$authPass('product.amzProductSale.save')" @click="showAddGoodsDialog = true">添加在线商品</a-button>
            <a-button class="gray-outline" size="medium" v-if="$authPass('product.amzProductSale.updateSalerBatch')" @click="openChooseUser">匹配销售员</a-button>
            <a-dropdown :popup-max-height="false">
              <a-button class="gray-outline">批量操作 <icon-down /></a-button>
              <template #content>
                <!-- <a-doption>调价</a-doption> -->
                <!-- <a-doption>修改listing信息</a-doption> -->
                <!-- <a-doption @click="openPackagingDialog">批量维护包装</a-doption> -->
                <a-doption @click="openToProductDialog" v-if="$authPass('product.amzProductSale.convertProductBatch')">批量转产品库</a-doption>
                <a-doption @click="openSetTimeDialog(selectRow)" v-if="$authPass('product.amzProductSale.updateGmtWarhousingBatch')">设置首次入仓时间</a-doption>
                <a-doption @click="openPrintLabel">打印标签</a-doption>
              </template>
            </a-dropdown>
            <a-dropdown :popup-max-height="false">
              <a-button class="gray-outline">关联 <icon-down /></a-button>
              <template #content>
                <a-doption @click="openChooseProductDialog(selectRow)" v-if="$authPass('product.amzProductSale.bindProductBatch')">批量关联SKU</a-doption>
                <a-doption @click="showImportPairDialog = true" v-if="$authPass('product.amzProductSale.importBindProduct')">导入关联SKU和销售员</a-doption>
                <a-doption @click="showSetAutoDialog = true">自动识别关联设置</a-doption>
              </template>
            </a-dropdown>
            <a-dropdown :popup-max-height="false">
              <a-button class="gray-outline">同步 <icon-down /></a-button>
              <template #content>
                <a-doption @click="syncAmzProductByIds(syncAmzProductSalesByIds, 'idList')" v-if="$authPass('product.amzProductSale.syncAmzProductSalesByIds')">更新商品信息</a-doption>
                <a-doption @click="syncAmzProductByIds(syncFnSkus, 'idList')" v-if="$authPass('product.amzProductSale.syncFnSkus')">同步FNSKU</a-doption>
                <a-doption @click="showSyncGoodsDialog = true" v-if="$authPass('product.amzProductSale.syncAmzProductSalesByShops')">同步新商品</a-doption>
                <a-doption @click="syncAmzProductByIds(syncReplenishByProduct, 'productSaleIds')">同步到智能补货</a-doption>
              </template>
            </a-dropdown>
            <div>
              <span>已选</span>
              <span class="highlight" style="margin-left: 10px">{{ selectRow.length }}</span>
            </div>
            <a-button type="text" size="medium" @click="clearSelect">清除已选</a-button>
          </a-space>
        </template>
        <!-- <template #headerRight>
          <a-button class="gray-outline" size="medium" @click="showTaskProgressDialog = true">任务进度</a-button>
        </template> -->
        <template #tableBody>
          <a-table
            class="table-two-line show-border-table"
            ref="tableRef"
            row-key="id"
            :loading="tableLoading"
            @selection-change="selectColumn"
            :row-selection="rowSelection"
            :bordered="true"
            :data="goodsList"
            :scroll="{
              x: '100%',
              y: '100%',
            }"
            size="mini"
            :pagination="false"
          >
            <template #columns>
              <a-table-column :width="40" data-index="expand" v-if="searchVal.modelType == 2" fixed="left">
                <template #title>
                  <span class="expand-all-btn" @click="changeExpandAll">
                    <icon-plus v-show="!expandAll" />
                    <icon-minus v-show="expandAll" />
                  </span>
                </template>
              </a-table-column>
              <a-table-column :width="70" title="类型" v-if="searchVal.modelType == 2" fixed="left">
                <template #cell="{ record }">
                  <p v-if="record.isParent">变体({{ record.children.length }})</p>
                  <p v-else>子体</p>
                </template>
              </a-table-column>
              <a-table-column :width="60" title="状态" fixed="left">
                <template #cell="{ record }">
                  <p>{{ OnlineGoodsStatus[record.status] }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="60" title="图片" fixed="left">
                <template #cell="{ record }">
                  <ImgPopover :src="getMainUrl(record)">
                    <template #con>
                      <a-image width="40" height="40" fit="contain" :src="getMainUrl(record)" />
                    </template>
                  </ImgPopover>
                </template>
              </a-table-column>
              <a-table-column :width="100" title="ASIN" fixed="left">
                <template #cell="{ record }">
                  <p class="highlight">{{ record.asin }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="130" title="MSKU/FNSKU" fixed="left">
                <template #cell="{ record }">
                  <TextLimit :val="record.msku || '--'" :rows="1" />
                  <TextLimit :val="record.fnSku || '--'" :rows="1" />
                </template>
              </a-table-column>
              <a-table-column :width="140" title="店铺/站点" fixed="left">
                <template #cell="{ record }">
                  <TextLimit :val="record.shopName" :rows="1" />
                  <p style="color: #ccc">{{ $extract(marketPlaceList[record.marketplaceId], 'name') }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="300" title="商品标题">
                <template #cell="{ record }">
                  <a-popover position="bottom" style="width: 400px" v-if="!record.isParent">
                    <p class="text-limit-two">{{ record.name }}</p>
                    <template #content>
                      <p>{{ record.name }}</p>
                    </template>
                  </a-popover>
                  <p v-else>--</p>
                </template>
              </a-table-column>
              <a-table-column :width="140" title="SKU/品类">
                <template #cell="{ record }">
                  <a-space v-if="!record.isParent">
                    <div v-if="$extract(record, 'product.sku')">
                      <ShowSpuDetailBySku :val="$extract(record, 'product.sku')" :showLimit="false" />
                      <p>{{ $extract(record, 'category.highParentName') }}</p>
                    </div>
                    <i v-if="$authPass('product.amzProductSale.bindProductBatch')" class="icon icon-guanlian highlight" @click="openChooseProductDialog([record.id])"></i>
                  </a-space>
                  <p v-else>--</p>
                </template>
              </a-table-column>
              <a-table-column :width="120" title="父ASIN">
                <template #cell="{ record }">
                  <p v-if="!record.isParent">{{ getParentAsinList(record) }}</p>
                  <p v-else>--</p>
                </template>
              </a-table-column>
              <a-table-column :width="60" title="销售员">
                <template #cell="{ record }">
                  <p>{{ $extract(record, 'saler.name') }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="90" title="价格">
                <template #cell="{ record }">
                  <p>{{ getCurrency(record.marketplaceId) }} {{ record.price }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="95" data-index="thirtyDaysSalesSum" title="30天销量" :sortable="{ sortDirections: ['ascend', 'descend'] }" />
              <a-table-column :width="80" title="配送渠道">
                <template #cell="{ record }">
                  <p>{{ DeliveryChannel[record.channel] }}</p>
                </template>
              </a-table-column>
              <!-- <a-table-column :width="110" title="包装">
                <template #cell>
                  <p>HUKKUN小盒子</p>
                </template>
              </a-table-column> -->
              <a-table-column :width="80" data-index="saleType" title="商品类型" />
              <a-table-column :width="135" title="上架时间" :sortable="{ sortDirections: ['ascend', 'descend'] }">
                <template #cell="{ record }">
                  <p>{{ $setTime(record.gmtOpen) }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="160" title="首次入仓时间" :sortable="{ sortDirections: ['ascend', 'descend'] }">
                <template #cell="{ record }">
                  <a-space>
                    <p>{{ $setTime(record.gmtWarehousing) }}</p>
                    <icon-edit v-if="$authPass('product.amzProductSale.updateGmtWarhousingBatch')" class="cursor" @click="openSetTimeDialog([record.id])" />
                  </a-space>
                </template>
              </a-table-column>
              <a-table-column :width="135" title="更新时间" :sortable="{ sortDirections: ['ascend', 'descend'] }">
                <template #cell="{ record }">
                  <p>{{ $setTime(record.gmtWrite) }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="135" title="创建时间" :sortable="{ sortDirections: ['ascend', 'descend'] }">
                <template #cell="{ record }">
                  <p>{{ $setTime(record.gmtCreate) }}</p>
                </template>
              </a-table-column>
              <a-table-column :width="60" title="操作" fixed="right">
                <template #cell="{ record }">
                  <a-button type="text" @click="openLogList(record)">日志</a-button>
                </template>
              </a-table-column>
            </template>
          </a-table>
        </template>
      </TableWrap>
      <div class="pagination-footer">
        <a-pagination size="mini" :total="total" :default-page-size="searchVal.pageSize" :current="searchVal.pageNum" :page-size-options="[20, 50, 100, 200, 500]" show-total show-page-size @page-size-change="sizeChange" @change="changePage" />
      </div>
    </div>
  </div>
  <!-- 添加在线商品 -->
  <AddOnlineGoods v-if="showAddGoodsDialog" :shopList="shopList" :userList="userList" :isShow="showAddGoodsDialog" @closed="showAddGoodsDialog = false" @success="getGoodsList" />
  <!-- 匹配销售员 -->
  <ChooseUser v-if="showUserDialog" title="匹配销售员" label="销售员" :multiple="false" :isShow="showUserDialog" :isRequired="true" :value-obj="true" @closed="showUserDialog = false" @success="editSales" />
  <!-- 维护包装 -->
  <SetPackaging v-if="showPackagingDialog" :isShow="showPackagingDialog" @closed="showPackagingDialog = false" @success="getGoodsList" />
  <!-- 设置首次入仓时间 -->
  <SetTime v-if="showSetTimeDialog" :isShow="showSetTimeDialog" :ids="currentList" @closed="showSetTimeDialog = false" @success="getGoodsList" />
  <!-- 匹配设置 -->
  <SetAuto v-if="showSetAutoDialog" :isShow="showSetAutoDialog" @closed="showSetAutoDialog = false" @success="getGoodsList" />
  <!-- 任务进度 -->
  <TaskProgress v-if="showTaskProgressDialog" :isShow="showTaskProgressDialog" @closed="showTaskProgressDialog = false" />
  <!-- 转产品库 -->
  <ToProduct v-if="showToProductDialog" :userList="userList" :currentList="currentList" :isShow="showToProductDialog" @closed="showToProductDialog = false" @success="getGoodsList" />
  <!-- 关联产品 -->
  <ChooseProduct v-if="showChooseProductDialog" title="批量关联产品" :isShow="showChooseProductDialog" @closed="showChooseProductDialog = false" @success="chooseProduct" />
  <!-- 导入配对 -->
  <ImportPair v-if="showImportPairDialog" :isShow="showImportPairDialog" @closed="showImportPairDialog = false" @success="getGoodsList" />
  <!-- 根据店铺同步商品 -->
  <SyncGoodsByShop v-if="showSyncGoodsDialog" :shopList="shopList" :isShow="showSyncGoodsDialog" @closed="showSyncGoodsDialog = false" />
  <!-- 批量打印标签 -->
  <PrintLabelDialog v-if="showPrintLabel" :isShow="showPrintLabel" :printConfig="printConfig" @closed="showPrintLabel = false" :disabledFontSize="true" :list="currentList" />
  <!-- 日志列表 -->
  <CommonLogsDialog v-if="showLogDialog" api="amzProductSaleLog" :id="currentList[0].id" :isShow="showLogDialog" @closed="showLogDialog = false" />
</template>
<script lang="ts">
  export default defineComponent({
    name: 'AmazonOnlineList',
  })
</script>
<script lang="ts" setup>
  import { defineComponent, ref, onMounted, reactive } from 'vue'
  import { getCategoryList } from '@/api/product'
  import FilterTable from '@/components/TableFilter.vue'
  import { FilterTableItem } from '@/types/components'
  import { getShopMarketAll, findShopMarketByParam, getOrganizesUser } from '@/api/system'
  import { OnlineGoodsStatus, DeliveryChannel } from '../types'
  import { marketPlaceList, currencySymbol } from '@/utils/globalData'
  import { getAmzProductSale, updateSalerBatch, bindProductBatch, syncAmzProductSalesByIds, syncFnSkus, syncReplenishByProduct } from '@/api/publish'
  import AddOnlineGoods from './components/addOnlineGoods.vue'
  import SetPackaging from './components/setPackaging.vue'
  import TaskProgress from './components/taskProgress.vue'
  import ToProduct from './components/toProduct.vue'
  import ChooseProduct from './components/chooseProduct.vue'
  import ImportPair from './components/importPair.vue'
  import SetTime from './components/setTime.vue'
  import SetAuto from './components/setAuto.vue'
  import SyncGoodsByShop from './components/syncGoodsByShop.vue'
  import ChooseUser from '@/components/ChooseUser.vue'
  import PrintLabelDialog from '@/components/Print/printLabelDialog.vue'
  import TableWrap from '@/components/TableWrap.vue'
  import { Message } from '@arco-design/web-vue'
  import CommonLogsDialog from '@/components/Log/logsDialog.vue'

  onMounted(() => {
    getGoodsList()
    getMarketList()
    getShopList()
    getUserList()
    getCategory()
  })
  const rowSelection = reactive({
    type: 'checkbox',
    showCheckedAll: true,
    onlyCurrent: false,
  }) as any

  const filterItem = ref<Array<FilterTableItem>>([
    {
      key: 'marketplaceIdList',
      label: '站点',
      value: ref(),
      type: 'select_multiple',
      width: 120,
      optionItems: [],
    },
    {
      key: 'sellerMarketIdList',
      label: '全部店铺',
      value: ref(),
      type: 'select_multiple',
      width: 120,
      optionItems: [],
    },
    {
      key: 'statusList',
      label: '状态',
      value: ref(),
      type: 'select_multiple',
      width: 120,
      optionItems: [
        {
          label: '在售',
          value: 'active',
        },
        {
          label: '不可售',
          value: 'inactive',
        },
        {
          label: '不完整',
          value: 'incomplete',
        },
        {
          label: '无报告',
          value: 'noListing',
        },
      ],
    },
    {
      key: 'categoryIdList',
      label: '品类',
      placeholder: '品类',
      value: ref(),
      type: 'cascader1',
      width: 120,
      optionItems: [],
      attrs: {
        checkStrictly: true,
        multiple: true,
        maxTagCount: 1,
        fieldNames: { value: 'id', label: 'name' },
        placeholder: '品类',
        formatLabel: (options: any) => {
          const labels = options.map((option: any) => option.name)
          return labels?.[labels.length - 1]
        },
      },
    },
    {
      key: 'isMatchProduct',
      label: '配对状态',
      value: ref(),
      type: 'select',
      width: 100,
      optionItems: [
        {
          label: '已配对',
          value: 'true',
        },
        {
          label: '未配对',
          value: 'false',
        },
      ],
    },
    {
      key: 'channel',
      label: '配送渠道',
      value: ref(),
      type: 'select',
      width: 115,
      optionItems: [
        {
          label: '亚马逊配送',
          value: 'AFN',
        },
        {
          label: '卖家自配送',
          value: 'MFN',
        },
      ],
    },
    {
      key: 'salerIdList',
      label: '销售员',
      value: ref(),
      type: 'select',
      width: 120,
      optionItems: [],
    },
    {
      type: 'input_keyword_type',
      key: 'product.sku',
      keyItems: [
        { label: 'ASIN', value: 'asin' },
        { label: '父ASIN', value: 'parentAsinList' },
        { label: 'MSKU', value: 'msku' },
        { label: 'FNSKU', value: 'fnSku' },
        { label: 'SKU', value: 'product.sku' },
        { label: '品名', value: 'name' },
      ],
      keyWidth: '90',
      value: ref(),
      placeholder: '请输入',
      label: '',
      width: 160,
      isMultiple: false,
    },
    {
      type: 'keyword_date_range',
      key: 'gmtCreate',
      keyItems: [
        { label: '创建时间', value: 'gmtCreate' },
        { label: '更新时间', value: 'gmtWrite' },
        { label: '上架时间', value: 'gmtOpen' },
        { label: '首次入仓时间', value: 'gmtWarehousing' },
      ],
      keyWidth: '130',
      value: ref(),
      placeholder: '请输入',
      label: '创建时间',
      width: 240,
      attrs: {
        valueFormat: 'YYYY-MM-DD HH:mm:ss',
        timePickerProps: { defaultValue: ['00:00:00', '23:59:59'] },
      },
    },
  ])

  let searchVal = ref({
    pageSize: 20,
    pageNum: 1,
    modelType: 1,
  })
  const expandAll = ref(false)
  const total = ref(0)
  const tableLoading = ref(false)
  const goodsList = ref<Array<any>>([])
  const selectRow = ref([])
  const goodsListMap = ref({})
  const showAddGoodsDialog = ref(false)
  const showUserDialog = ref(false)
  const showSetTimeDialog = ref(false)
  const showSetAutoDialog = ref(false)
  const showPackagingDialog = ref(false)
  const showTaskProgressDialog = ref(false)
  const showToProductDialog = ref(false)
  const showChooseProductDialog = ref(false)
  const showImportPairDialog = ref(false)
  const showSyncGoodsDialog = ref(false)
  const showPrintLabel = ref(false)
  const showLogDialog = ref(false)
  const tableRef = ref()
  const currentList = ref<Array<any>>([])
  const userList = ref([])
  const shopList = ref<Array<any>>([])
  const categoryOptions = ref<Array<any>>([])
  const markedtList = ref<Array<any>>([])
  const filterData = ref<any>({})
  const printConfig = ref<any>({})

  const selectColumn = (val: any) => {
    selectRow.value = val
  }
  // 币种
  function getCurrency(marketPlaceId: string) {
    return currencySymbol[marketPlaceList[marketPlaceId]?.currency]
  }
  // 批量打印标签
  function openPrintLabel() {
    currentList.value = []
    selectRow.value.forEach((id) => {
      let _data: any = goodsListMap.value[id]
      if (_data.fnSku) {
        currentList.value.push({
          img: getMainUrl(_data),
          msku: _data.msku,
          fnsku: _data.fnSku,
          asin: _data.asin,
          sku: _data?.product?.sku,
          productName: _data.name,
          id: _data.id,
          new: 'New',
        })
      }
    })
    if (!currentList.value?.length) {
      return Message.error('最少选择一个有fnsku的产品！')
    }
    printConfig.value.tableColumns = [
      {
        title: '图片',
        dataIndex: 'img',
        isLimit: false,
        width: 60,
      },
      {
        title: 'MSKU',
        dataIndex: 'msku',
        isLimit: true,
        width: 120,
      },
      {
        title: 'FNSKU',
        dataIndex: 'fnsku',
        isLimit: true,
        width: 120,
      },
      {
        title: 'ASIN',
        dataIndex: 'asin',
        isLimit: true,
        width: 100,
      },
      {
        title: 'SKU',
        dataIndex: 'sku',
        isLimit: true,
        width: 120,
      },
      {
        title: '产品名称',
        dataIndex: 'productName',
        isLimit: true,
        width: 120,
      },
      {
        title: '打印数量',
        dataIndex: 'printNum',
        isLimit: false,
        width: 120,
      },
    ]
    printConfig.value.allFieldList = {
      fnsku: { name: 'FNSKU', key: 'fnsku', defaultVal: 'X003R61BTJ', fontSize: 10 },
      asin: { name: 'ASIN', key: 'asin', defaultVal: 'B0CJXP2Q2W', fontSize: 10 },
      msku: { name: 'MSKU', key: 'msku', defaultVal: 'WMX10842-HKP', fontSize: 10 },
      productName: { name: '产品名称', key: 'productName', defaultVal: 'Horse Gifts for Women', fontSize: 8, lengthLimit: true },
      sku: { name: 'SKU', key: 'sku', defaultVal: 'WME20815KP', fontSize: 10 },
      new: { name: 'New', key: 'new', defaultVal: 'New', fontSize: 8 },
    }
    printConfig.value.fieldList = ['fnsku', 'productName', 'new']

    showPrintLabel.value = true
  }
  // 获取所有用户列表
  async function getUserList() {
    const res: any = await getOrganizesUser({
      pageNum: 1,
      pageSize: 1000,
    })
    userList.value = res?.data?.records || []
    filterItem.value[6].optionItems = userList.value?.map((el: any) => {
      return {
        label: el.userName,
        value: el.id,
      }
    })
  }
  // 获取站点
  async function getMarketList() {
    const res: any = await getShopMarketAll()
    markedtList.value = res?.data || []
    filterItem.value[0].optionItems = res?.data?.map((el: any) => {
      return {
        label: el.marketplaceName,
        value: el.marketplaceId,
      }
    })
  }
  // 获取店铺
  async function getShopList() {
    const res: any = await findShopMarketByParam()
    shopList.value = res?.data || []
    filterItem.value[1].optionItems = res?.data?.map((el: any) => {
      return {
        label: el.shopName,
        value: el.sellerMarketId,
      }
    })
  }
  async function getCategory() {
    const res: any = await getCategoryList()
    categoryOptions.value = res?.data || []
    filterItem.value[3].optionItems = res.data
  }
  // 打开日志列表
  function openLogList(row: any) {
    currentList.value = [row]
    showLogDialog.value = true
  }
  // 分页
  function changePage(val: number) {
    searchVal.value.pageNum = val
    getGoodsList()
  }
  function sizeChange(val: number) {
    searchVal.value.pageSize = val
    getGoodsList()
  }
  // 清除选中
  function clearSelect() {
    tableRef.value.selectAll(false)
  }
  // 折叠展开全部
  function changeExpandAll() {
    expandAll.value = !expandAll.value
    tableRef.value.expandAll(expandAll.value)
  }
  // 通过条件查询用户列表
  function searchByVal(info: any) {
    searchVal.value.pageNum = 1
    filterData.value = JSON.parse(JSON.stringify(info)) || {}
    getGoodsList()
  }
  // 获取商品列表
  async function getGoodsList() {
    let params = {
      pageNum: searchVal.value.pageNum,
      pageSize: searchVal.value.pageSize,
      ...filterData.value,
    }
    tableRef.value.selectAll(false)
    if (searchVal.value.modelType === 1) {
      params.isChild = true
    } else {
      params.isParent = true
    }
    tableLoading.value = true
    const res: any = await getAmzProductSale(params)
    tableLoading.value = false
    goodsList.value = res?.data?.records || []
    total.value = res?.data?.total || 0
    setGoodsData()
  }
  // 处理数据
  function setGoodsData() {
    goodsListMap.value = {}
    if (searchVal.value.modelType === 2) {
      // 父ASIN
      goodsList.value.forEach((el) => {
        el.children = el.childs || []
        delete el.childs
        goodsListMap.value[el.id] = el
        console.log(el.children)
        el.children.forEach((item: any) => {
          goodsListMap.value[item.id] = el
        })
      })
      tableRef.value.expandAll(false)
      expandAll.value = false
    } else {
      // 子ASIN
      goodsList.value.forEach((el) => {
        goodsListMap.value[el.id] = el
      })
    }
  }
  // 显示图片
  function getMainUrl(row: any) {
    return row?.imageList?.[0]?.link
  }
  // 显示父ASIN
  function getParentAsinList(row: any) {
    return row?.parentAsinList?.join(',')
  }
  // 打开匹配销售员
  function openChooseUser() {
    if (!selectRow.value.length) {
      return Message.error('请选择商品')
    }
    showUserDialog.value = true
  }
  // 编辑销售员
  async function editSales(users: any) {
    const res: any = await updateSalerBatch({
      idList: selectRow.value,
      userId: users.id,
      userName: users.userName,
    })
    if (res) {
      Message.success('设置成功')
      getGoodsList()
    }
  }
  // 打开设置包装
  // function openPackagingDialog() {
  //   if (!selectRow.value.length) {
  //     return Message.error('请选择商品')
  //   }
  //   showPackagingDialog.value = true
  // }
  // 打开设置首次入仓时间
  function openSetTimeDialog(ids: Array<any>) {
    currentList.value = [...ids]
    if (!currentList.value.length) {
      return Message.error('请选择商品')
    }
    showSetTimeDialog.value = true
  }

  // 打开转产品库
  function openToProductDialog() {
    if (!selectRow.value.length) {
      return Message.error('请选择商品')
    }
    currentList.value = []
    selectRow.value.map((id) => {
      let _data: any = goodsListMap.value[id]
      if (_data.isParent) {
        currentList.value = [...currentList.value, ...(_data.children || [])]
      } else {
        currentList.value.push(_data)
      }
    })
    showToProductDialog.value = true
  }
  // 打开产品配对
  function openChooseProductDialog(ids: Array<any>) {
    currentList.value = [...ids]
    if (!currentList.value.length) {
      return Message.error('请选择商品')
    }
    showChooseProductDialog.value = true
  }
  // 选择产品开始配对
  async function chooseProduct(product: any) {
    const res: any = await bindProductBatch({
      productId: product.id,
      amzProductSaleIdList: currentList.value,
    })
    if (res) {
      Message.success('关联成功')
      getGoodsList()
    }
  }
  //更新商品信息和同步FnSku
  async function syncAmzProductByIds(synsMethods: any, key: string) {
    if (!selectRow.value.length) {
      return Message.error('请选择商品')
    }
    let _params: any = {}
    _params[key] = selectRow.value
    const res: any = await synsMethods(_params)
    if (res) {
      Message.success('同步成功')
      getGoodsList()
    }
  }
</script>
<style lang="less" scoped>
  .expand-all-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 14px;
    height: 14px;
    padding: 0;
    color: var(--color-text-2);
    font-size: 12px;
    line-height: 14px;
    background-color: var(--color-neutral-3);
    border: 1px solid transparent;
    border-radius: 2px;
    outline: none;
    cursor: pointer;
    transition: background-color 0.1s cubic-bezier(0, 0, 1, 1);
  }
</style>
